package com.shsubway.adapter;

import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shsubway.R;
import com.shsubway.model.AnswerEntity;

import java.util.List;

/**
 * Created by Hu on 2017/3/2.
 */

public class QuesFragmentAdapter extends BaseQuickAdapter<AnswerEntity, BaseViewHolder> {
    int type;

    public QuesFragmentAdapter(int layoutResId, List<AnswerEntity> data, int type) {
        super(layoutResId, data);
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, AnswerEntity item) {
        helper
                .setText(R.id.choose_id, getA2Z(helper.getAdapterPosition() - 1) + ":")
                .addOnClickListener(R.id.choose_isture)
                .setText(R.id.choose_ans, item.getAnscontent());
        CheckBox checkBox = helper.getView(R.id.choose_isture);
        checkBox.setChecked(item.isTure());
        checkBox .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (type==0){
                    item.setTure(isChecked);
                    checkBox.setChecked(item.isTure());
                }else {
                    checkBox.setChecked(!isChecked);
                }
            }
        });

// helper
//                .setText(R.id.choose_id, getA2Z(helper.getAdapterPosition() - 1) + ":")
//                .setBackgroundRes(R.id.choose_isture, type==0?R.mipmap.choose_no:item.isTure() ? R.mipmap.choose_true : R.mipmap.choose_no)
//                .addOnClickListener(R.id.choose_isture)
//                .setText(R.id.choose_ans, item.getAnscontent());
    }

    private String getA2Z(int i) {
        return String.valueOf((char) (65 + i));

    }
}
